﻿-- =========================================================================================================
-- Author:		MICHAEL RITACCO
-- Copyright:	2010 MEKHANO GROUP LLC
-- Version:		08/21/2010 1.0
-- =========================================================================================================
CREATE PROCEDURE [flcr].[api_device_sel_lov]
	@DEVICE_ID INT = NULL
	,@DEVICE_TYPE INT = NULL
	,@DOMAIN_ID INT = NULL

AS
BEGIN TRY
  
	SELECT	B.[DOMAIN_NAME]
			,A.[DEVICE_ID] 
			,A.[DEVICE_ASSET_NAME]
			,A.[PARENT_ID]
			,A.[DEVICE_TYPE]
			,C.[DEVICE_TYPE_NAME]
	  FROM	[flcr].[DEVICE] A
	 INNER JOIN [flcr].[DOMAIN] B
		ON	A.[DOMAIN_ID] = B.[DOMAIN_ID]
	 INNER JOIN flcr.[DEVICE_TYPE] C
		ON  A.[DEVICE_TYPE] = C.[DEVICE_TYPE] 
	 WHERE	A.[DEVICE_ID] = COALESCE(@DEVICE_ID, A.[DEVICE_ID])
	   AND	A.[DEVICE_TYPE] = COALESCE(@DEVICE_TYPE, A.[DEVICE_TYPE])
	   AND	B.[DOMAIN_ID] =  COALESCE(@DOMAIN_ID, B.[DOMAIN_ID])  

END TRY
BEGIN CATCH
	EXEC [flcr].[utl_getDBError];
END CATCH